<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="/common/taglibs.jsp" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>系统管理</title>
    <link href="${cdnctx}/dep/jquery/jquery-ui-1.10.2.custom.css" rel="stylesheet" type="text/css"/>
    <%@ include file="/common/util.jsp" %>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#devicetypeid").change(function () {
                var device = $("#devicetypeid").val();
                if (device == 419) {
                    $("#relevance").show();
                } else {
                    $("#relevancename").val('');
                    $("#relevance").hide();
                }
            });

            $("#addAreaPointForm").validate({
                rules: {
                    'pointname': {
                        required: true
                    },
                    'sensorid': {
                        required: true,
                        digits: true,
                        maxlength: 4
                    },
                    'gatewayid': {
                        required: true
                    },
                    'channelid': {
                        required: true,
                        digits: true,
                        maxlength: 10
                    },
                    'devicetypeid': {
                        required: true
                    }
                },
                messages: {
                    'pointname': {
                        required: "节点名称"
                    },
                    'sensorid': {
                        required: "设备ID",
                        digits: "请输入合法的ID格式",
                        maxlength: $.validator.format("请输入不超过{0}位数的ID")
                    },
                    'channelid': {
                        required: "通道ID",
                        digits: "请输入合法的ID格式",
                        maxlength: $.validator.format("请输入不超过{0}位数的ID")
                    },
                    'gatewayid': {
                        required: "网关名称"
                    },
                    'devicetypeid': {
                        required: "设备类型"
                    }
                },
                submitHandler: function (form) {
                    var areaPoint = {
                        "id": $('#id').val(),
                        "gatewayid": $('#gatewayid').val(),
                        "sensorid": $('#sensorid').val(),
                        "channelid": $('#channelid').val()
                    };
                   // console.log(areaPoint);
                    $.ajax({
                        contentType: "application/json",
                        url: "${cdnctx}/systemAreaPoint/existAreaPoint.shtml",
                        data: areaPoint,
                        async: false,
                        dataType: "json",
                        success: function (data) {
                            var flag = data.existFlag;
                            if (flag)
                                form.submit();
                            else {
                                $('#areaPointExist').show();
                                $('#areaPointExist').delay(3000).hide(0);
                            }
                        }
                    });
                }
            });
        });

    </script>
</head>
<body class="main">
<div class="-frame -style -luster" id="css_container">
    <!--首页框架页眉部分↓-->
    <%@ include file="/WEB-INF/pages/inc/header.jsp" %>
    <!--首页框架页眉部分↑-->

    <div class="content">

        <!-- Left导航菜单◎开始 -->
        <%@ include file="/WEB-INF/pages/inc/leftmenu.jsp" %>
        <!-- Left导航菜单◎结束 -->

        <div class="main-mid">
            <div class="pos"><img src="${cdnctx}/src/index/img/index.png"><a
                    href="<%--${cdnctx}/system/systemMenu.shtml--%>">系统管理 </a>
                ><a href="${cdnctx}/system/customerinfo/customerMain.shtml">公司信息管理</a>
                ><a href="${cdnctx}/systemCustomerArea/customerAreaList.shtml?customerinfoid=${customerArea.customerinfoid }">${customerArea.companyname }</a>
                ><a href="${cdnctx}/systemAreaPoint/areaPointList.shtml?areaid=${customerArea.id}">${customerArea.areaname }</a>
                ><a><c:if test="${empty areapoints }">添加</c:if> <c:if test="${not empty areapoints }">编辑</c:if> 采集节点</a>
            </div>

            <div class="css_contentDiv">
                <div class="searchDetailed">
                    <form id="addAreaPointForm" method="post" action="${cdnctx}/systemAreaPoint/saveAreaPoint.shtml">
                        <input type="hidden" name="customerinfoid" value="${customerArea.customerinfoid }"/>
                        <input type="hidden" name="areaid" id="areaid" value="${customerArea.id }"/>
                        <input type="hidden" name="id" id="id" value="${areapoints.id }"/>
                        <table align="center" id="table" width="800" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td class="mainText"><label class="formlabel"><font color="red">*</font>节点名称：</label>
                                </td>
                                <td>
                                    <input type="text" id="pointname" name="pointname" class="form_input large"
                                           value="${areapoints.pointname }">
                                </td>
                            </tr>
                            <tr>
                                <td class="mainText"><label class="formlabel"><font color="red">*</font>网关：</label></td>
                                <td>
                                    <input type="text" class="form_input large" name="gatewayid" id="gatewayid"
                                           value="${areapoints.gatewayid }"/>
                                </td>
                            </tr>
                            <tr>
                                <td class="mainText"><label class="formlabel"><font color="red">*</font>设备：</label></td>
                                <td>
                                    <input type="text" class="form_input large" name="sensorid" id="sensorid"
                                           value="${areapoints.sensorid }" maxlength="40"/>
                                </td>
                            </tr>
                            <tr>
                                <td class="mainText"><label class="formlabel"><font color="red">*</font>通道：</label></td>
                                <td>
                                    <input type="text" class="form_input large" name="channelid" id="channelid"
                                           value="${areapoints.channelid }" maxlength="40"/>
                                    <span id="areaPointExist" style="display: none; color: #b92c28">该节点已存在</span>
                                </td>
                            </tr>
                            <tr>
                            <tr>
                                <td>设备类型</td>
                                <td>
                                    <select id="devicetypeid" name="devicetypeid" class="form_select large">
                                        <option value="">---请选择---</option>
                                        <c:forEach items="${deviceType }" var="entity">
                                            <option value="${entity.id }"
                                                    <c:if test="${entity.id == areapoints.devicetypeid }">selected='selected'</c:if>>${entity.name }</option>
                                        </c:forEach>
                                    </select>
                                </td>
                            </tr>
                            <tr id="relevance"  <c:if test="${419 != areapoints.devicetypeid }">style="display:none;"</c:if>>
                                <td>空调名称：</td>
                                <td>
                                    <input type="text" class="form_input large" name="relevancename" id="relevancename"
                                           value="${areapoints.relevancename }" maxlength="40"/>
                                </td>
                            </tr>
                            <tr>
                                <td></td>
                                <td>
                                    <input type="submit" class="form_save" value="保&nbsp;存"/>
                                    <input type="reset" class="form_cancle" value="取&nbsp;消"/>
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
            </div>
        </div>

    </div>

    <!--首页框架页尾部分↓-->
    <%@ include file="/WEB-INF/pages/inc/footer.jsp" %>
    <!--首页框架页尾部分↑-->
</div>
</body>
</html>